import { t } from '@/locales/i18n';
import { LLMModelTypeEnum } from '@/types/ai/constants';
import {
  FlowNodeInputTypeEnum,
  FlowNodeOutputTypeEnum,
  FlowNodeTemplateTypeEnum,
  FlowNodeTypeEnum,
  NodeInputKeyEnum,
  NodeOutputKeyEnum,
  WorkflowIOValueTypeEnum,
} from '@/types/workflow/constant';
import { FlowNodeTemplateType } from '@/types/workflow/node';

import { Input_Template_History, Input_Template_SelectAIModel } from '../../input';
import { getHandleConfig } from '../../utils';

export const ContextExtractModule: FlowNodeTemplateType = {
  id: FlowNodeTypeEnum.contentExtract,
  templateType: FlowNodeTemplateTypeEnum.ai,
  flowNodeType: FlowNodeTypeEnum.contentExtract,
  sourceHandle: getHandleConfig(true, true, true, true),
  targetHandle: getHandleConfig(true, true, true, true),
  avatar: 'extractJson.svg',
  name: t('text_content_extraction'),
  intro: t('workflow.content_extraction_desc'),
  showStatus: true,
  isTool: true,
  courseUrl: '/docs/workflow/modules/content_extract/',
  version: '481',
  isFolded: true,
  inputs: [
    {
      ...Input_Template_SelectAIModel,
      llmModelType: LLMModelTypeEnum.extractFields,
    },
    {
      key: NodeInputKeyEnum.description,
      renderTypeList: [FlowNodeInputTypeEnum.textarea, FlowNodeInputTypeEnum.reference],
      valueType: WorkflowIOValueTypeEnum.string,
      label: t('extraction_requirements_description'),
      description: t('extraction_requirements_description_detail'),
      placeholder: t('extraction_requirements_placeholder'),
    },
    Input_Template_History,
    {
      key: NodeInputKeyEnum.contextExtractInput,
      renderTypeList: [FlowNodeInputTypeEnum.reference, FlowNodeInputTypeEnum.textarea],
      label: t('text_to_extract'),
      required: true,
      valueType: WorkflowIOValueTypeEnum.string,
      toolDescription: t('content_to_retrieve'),
    },
    {
      key: NodeInputKeyEnum.extractKeys,
      renderTypeList: [FlowNodeInputTypeEnum.custom],
      label: '',
      valueType: WorkflowIOValueTypeEnum.any,
      description: t('target_fields_description'),
      value: [], // {valueType: string; desc: string; key: string; required: boolean; enum: string[]}[]
    },
  ],
  outputs: [
    {
      id: NodeOutputKeyEnum.success,
      key: NodeOutputKeyEnum.success,
      label: t('full_field_extraction'),
      required: true,
      description: t('full_field_extraction_description'),
      valueType: WorkflowIOValueTypeEnum.boolean,
      type: FlowNodeOutputTypeEnum.static,
    },
    {
      id: NodeOutputKeyEnum.contextExtractFields,
      key: NodeOutputKeyEnum.contextExtractFields,
      label: t('complete_extraction_result'),
      required: true,
      description: t('complete_extraction_result_description'),
      valueType: WorkflowIOValueTypeEnum.string,
      type: FlowNodeOutputTypeEnum.static,
    },
  ],
};
